import { Navigate, createBrowserRouter, RouteObject } from "react-router-dom"
import { lazy } from "react"
import Login from "@/pages/login"
import Main from "@/pages/main"

// 懒加载导入路由 
const Home = lazy(() => import("@/pages/home"))
const Mall = lazy(() => import("@/pages/mall"))
const User = lazy(() => import("@/pages/user"))
const PageOne = lazy(() => import("@/pages/other/pageOne"))
const PageTwo = lazy(() => import("@/pages/other/pageTwo"))
const ErrorPage = lazy(() => import("@/pages/errorPage"))

const routes: RouteObject[] = [
    {
        path: '/',
        element: <Main />,
        children: [
            // 重定向
            {
                path: '/',
                element: <Navigate to='home' replace/>
            },
            {
                path: 'home',
                element: <Home />
            },
            {
                path: 'mall',
                element: <Mall />
            },
            {
                path:'user',
                element: <User />
            },
            {
                path: 'other',
                children: [
                    {
                        path: 'pageOne',
                        element: <PageOne />
                    },
                    {
                        path: 'pageTwo',
                        element: <PageTwo />
                    }
                ]
            }
        ]
    },
    {
        path: '/login',
        element: <Login />
    }, 
    {
        path: '*',
        element: <ErrorPage />
    }
]

export default createBrowserRouter(routes)

